<?php
/**
* The Template for displaying all single posts.
*/

get_header();

	// SIDEBAR
	$content_class = ' class="position_left content_single_sidebar"';
	$sidebar_class = ' class="position_right single_sidebar"';

	$website_selected_position = get_option('sidebar_position');
	
	if ( $website_selected_position == 'left' )
	{
		$content_class = ' class="position_right content_single_sidebar"';
		$sidebar_class = ' class="position_left single_sidebar"';
	}
	
	$display_featured_image = get_post_meta($post->ID, 'display_featured_image', true);

?>

	<section id="content_wrapper" class="clearfix">
        <?php
        
		if ( $website_selected_position != 'off' )
		{
			echo '<div id="content_with_sidebar"'; echo $content_class; echo '>';
		}
		?>
            <div class="page_content">
                <?php
				
				if ( have_posts() ) while ( have_posts() ) : the_post(); 
				global $more; 
				$more = 1;
				
					$breadcrumb_active = get_option('breadcrumb_active');
					
					if ( $breadcrumb_active == 'yes' )
					{
						echo '<div class="breadcrumbs">';
							if(class_exists('bcn_breadcrumb_trail'))
							{
								//Make new breadcrumb object
								$breadcrumb_trail = new bcn_breadcrumb_trail;
								//Setup our options
								//Set the home_title to Blog
								$breadcrumb_trail->opt['home_title'] = "Home";
								//Set the current item to be surrounded by a span element, start with the prefix
								$breadcrumb_trail->opt['current_item_prefix'] = '<span class="current">';
								//Set the suffix to close the span tag
								$breadcrumb_trail->opt['current_item_suffix'] = '</span>';
								//Fill the breadcrumb trail
								$breadcrumb_trail->fill();
								//Display the trail
								$breadcrumb_trail->display();
							}
						echo '</div>';
					}
				
					if ( has_post_thumbnail() ) 
					{
						if ( $display_featured_image != 'no' && $display_featured_image != 'video' && $display_featured_image != 'slideshow' )
						{
							$thumbnail_src = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
						
							$thumbnail_size = 'w=630';
							if ( $website_selected_position == 'off' )
								$thumbnail_size = 'w=960';
								
							$image_source = get_template_directory_uri().'/includes/timthumb.php?src='.$thumbnail_src.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
							
							echo '<img style="display:block; margin-top: 1px;" src="'.$image_source.'" alt="'; echo the_title(); echo '" />';
						}
					}
					
					// START VIDEO
					if ( $display_featured_image == 'video' )
					{
						$featured_video = get_post_meta($post->ID, 'featured_video_link', true);
						echo $featured_video;
					}
					// END VIDEO
					
					// START SLIDESHOW
					if ( $display_featured_image == 'slideshow' )
					{
						$attached_images =& get_children('post_type=attachment&post_mime_type=image&post_parent='.$post->ID.'&order=ASC' );
						$attached_images = array_values($attached_images);
						
						if ( !empty($attached_images) )
                        {
							echo '
							<script type="text/javascript">
                            	jQuery(window).load(function() {
                                	jQuery("#single_slideshow").nivoSlider({effect:"fade",directionNav:true,manualAdvance:true});
								});
                            </script> 
							';
							
							$single_slideshow_width = '630';
							if ( $website_selected_position == 'off' )
								$single_slideshow_width = '960';
							
							$single_slideshow_height = get_post_meta($post->ID, 'single_slideshow_height', true);
							
							if ( $single_slideshow_height == '' )
								$single_slideshow_height = '300';
							
                            echo '<div id="single_slideshow" style="overflow: hidden; height: '.$single_slideshow_height.'px;">';
                                foreach ($attached_images as $attached_image)
								{
									echo '<a rel="prettyPhoto[single_slideshow]" href="'.$attached_image->guid.'">';
										echo '<img src="';
										echo get_template_directory_uri().'/includes/timthumb.php?src=';
										echo $attached_image->guid;
										echo '&amp;h='.$single_slideshow_height.'&amp;w='.$single_slideshow_width.'&amp;zc=1&amp;q=100"';
										echo ' alt="'; echo the_title(); echo '" />';
									echo '</a>';
								}
                            echo '</div>';
						}
					}
					// END SLIDESHOW
					
				
                    echo '<div id="single"' ; post_class(); echo '>';
                        echo '<h3 class="post_title">';
							the_title();
                        echo '</h3>';
    
                        echo '<div class="post_meta">';

							echo '<span class="date">';
								echo __( 'Posted on: ', 'reFresh' ); 
								echo '<a href="'; echo the_permalink(); echo '" title="'; the_title(); echo '">';
									echo get_the_date('jS F Y'); 
								echo '</a>';
							echo '</span>';
							
							echo '<span class="by">';
								echo __( 'by: ', 'reFresh' ); echo '<a href="'; echo get_author_posts_url( get_the_author_meta( 'ID' ) ); echo '" title="'; echo get_the_author(); echo '">'; echo get_the_author(); echo'</a>';
							echo '</span>';
							
							echo '<span class="categories">';
								echo __( 'Posted in: ', 'reFresh' ); echo get_the_category_list(', ');
								echo get_the_term_list( $post->ID, 'portfolio_category', '', ', ' );
							echo '</span>';
							
							$tag_list = get_the_tag_list('', ', ');
							if ($tag_list != '')
							{
								echo '<span class="tags">';
									echo __( 'Tags: ', 'reFresh' ); echo $tag_list;
								echo '</span>';
							}
							
							echo '<span class="comments">';
								echo __( 'Comments: ', 'reFresh' ); 
								echo '<a href="#comments" class="scroll">';
									comments_number('0', '1', '%');
								echo '</a>';
							echo '</span>';
							
                        echo '</div><!-- .post_meta -->'; // END .post_meta
						
						
                        echo '<div class="post_content clearfix">';
                            the_content('');
                        echo '</div><!-- .post_content -->';
                        
						/// DE ACI
    
						if ( get_option('article_enable_sharing', 'yes' ) == 'yes' )
						{
	
                        ?>
    
                            <div class="sharing clearfix">
                                <div class="facebook">
                                    <div id="fb-root"></div>
                                    <script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = "//connect.facebook.net/en_US/all.js#appId=284728074870751&xfbml=1";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>
                                    <div class="fb-like" data-send="false" data-layout="button_count" data-width="125" data-show-faces="false" data-colorscheme="light"></div>
                                </div>
                                    
                                <div class="twitter">
                                    <script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
                                    <a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a>
                                </div>
                                
                                <div class="google">                            
                                    <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
                                    <g:plusone size="medium"></g:plusone>
                                </div>
                                
                                <?php
                                if ( get_the_author_meta( 'description' ) ) // If a user has filled out their description, show a bio on their entries 
                                {
                                    echo '<div class="about_the_author">';
                                        echo '<div id="author_toggle_header">';
                                            printf( esc_attr__( 'About %s', 'reFresh' ), get_the_author() );;
                                        echo '</div>';
                                    echo '</div>';
                                }
                                ?>
                            </div><!-- #sharing -->
                        
							<?php
                            if ( get_the_author_meta( 'description' ) ) // If a user has filled out their description, show a bio on their entries 
                            {
                                ?>
                                <div id="author_toggle_content">
                                    <div id="author_info" class="clearfix">
                                        <div id="author_avatar">
                                            <?php echo get_avatar( get_the_author_meta( 'user_email' ),  76 ); ?>
                                        </div><!-- #author_avatar -->
                                        <div id="author_description">
                                            <div id="author_name">
                                                <?php echo get_the_author(); ?>
                                            </div>
                                            <div id="the_description">
                                                <?php the_author_meta( 'description' ); ?>
                                                <a id="author_link" href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
                                                    <?php printf( __( 'View all posts by %s', 'reFresh' ), get_the_author() ); ?>
                                                </a>
                                            </div>
                                        </div><!-- #author_description -->
                                    </div><!-- #author_info -->
                                </div>
                                <?php
                            }
                            
						} // END if ( get_option('article_enable_sharing', 'yes' ) == 'yes' )
						?>
                    
                     </div><!-- #single-->
                
				<?php
				
				$article_related_items = get_option('article_related_items');
				
				$show_post_number = 5;
				if ( $website_selected_position == 'off' )
				{
					$show_post_number = 7;	
				}
				if ( $article_related_items != 'off' )
				{
					$args = '';
					switch ( $article_related_items )
					{
						case 'category_related':
							$categories = get_the_category($post->ID);
							if ($categories)
							{
								$category_ids = array();
								foreach ($categories as $individual_category)
									$category_ids[] = $individual_category->term_id;
									
								$args = array('category__in' => $category_ids,
											  'post__not_in' => array($post->ID),
											  'showposts' => $show_post_number,
											  'ignore_sticky_posts' => 1
											  );
							}
						break;
						
						case 'tag_related':
							$tags = wp_get_post_tags($post->ID);
							if ($tags)
							{
								$tag_ids = array();
								foreach($tags as $individual_tag)
									$tag_ids[] = $individual_tag->term_id;
									
								$args = array('tag__in' => $tag_ids,
											  'post__not_in' => array($post->ID),
											  'showposts' => $show_post_number,
											  'ignore_sticky_posts' => 1
											  );
							}	
						break;							
					} // END switch ( $article_related_items )
					
					$my_query = new wp_query($args);
					if ( $my_query->have_posts() )
					{
						echo '<div id="related_items">';
							echo '<h3 class="related_title">';
								echo __( 'Related Items', 'reFresh' );
							echo '</h3>';
							echo '<div class="the_related_items clearfix">';
							
								$related_items_nr = 0;
								while ( $my_query->have_posts() )
								{
									$my_query->the_post();
									
									if ( has_post_thumbnail() ) $thumbnail_src = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
						
									$thumbnail_size = 'w=105&amp;h=105';
									$image_source = get_template_directory_uri().'/includes/timthumb.php?src='.$thumbnail_src.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
									
									echo '<div class="related_item"'; if ( $related_items_nr == $show_post_number-1 ) echo 'style="margin-right: 0px !important;"'; echo '>';
										echo '<a class="related_image" href="'; the_permalink(); echo '">';
											echo '<img src="'.$image_source.'" alt="'; echo the_title(); echo '" />';
										echo '</a>';
										
										echo '<a class="related_item_title" href="'; the_permalink(); echo '">';
											echo the_title();
										echo '</a>';
									echo '</div>';
									
									$related_items_nr++;
									
								} // END while ($my_query->have_posts())
								
							echo '</div>';
						echo '</div>';
					} // END if ( $my_query->have_posts() )
					
					wp_reset_query();
					
				} // END if ( $article_related_items != 'off' )
				
				if ( get_option('article_comments', 'yes') == 'yes' )
					comments_template( '', true );
				
				endwhile; // end of the loop.
				 // PANA ACI 

				?>
            </div><!-- .page_content -->
        
        <?php
        if ( $website_selected_position != 'off' )    
        	echo '</div> <!-- #content_with_sidebar -->';
		?>
        
        <?php
		if ( $website_selected_position != 'off' )
		{
			echo '<div id="sidebar"'.$sidebar_class.'>';
				echo '<div id="sidebar_content">';
					get_sidebar();
				echo '</div>';
			echo '</div>';
		}
        ?>
        
    </section> <!-- #content_wrapper -->



<?php get_footer(); ?>
